import {randomIntFromRange} from "./utils";
import Polygon from "./Polygon";

export default Barrier

/*
* x, y :坐标
* width: 宽度
* height: 高度
* gapUpperBound: 空隙中心的上界（实际坐标）
* gapLowerBound: 空隙中心的下界（实际坐标）
* gap: 中间的空隙大小
*/
function Barrier(x, y, width, height, gapUpperBound = 175, gapLowerBound = 325, color = "#7ECEFD", gap = 100) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.color = color;
    this.gap = gap;
    this.center = randomIntFromRange(gapUpperBound, gapLowerBound) - y;
    this.upPolygon = new Polygon(x, y,
        width, this.center - gap / 2,
        color, 'up');
    this.downPolygon = new Polygon(x, y + this.center + gap / 2,
        width, height - this.center - gap / 2,
        color, 'down');

    this.show = function () {
        this.upPolygon.x = this.x;
        this.upPolygon.y = this.y;
        this.downPolygon.x = this.x;
        this.downPolygon.y = this.y + this.center + this.gap / 2;
        this.upPolygon.show();
        this.downPolygon.show();
    }

    this.update = function () {
        this.upPolygon.x = this.x;
        this.upPolygon.y = this.y;
        this.downPolygon.x = this.x;
        this.downPolygon.y = this.y + this.center + this.gap / 2;
        this.upPolygon.show();
        this.downPolygon.show();
    }
}
